﻿using FRMS.DAL;
using FRMS.Model;
using FRMS_N71SP.BUS;
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Threading.Tasks;

namespace FRMS.TimedTask
{
    public class N71SPDeviceWork : IJob
    {
        public async Task Execute(IJobExecutionContext context)
        {
            DeviceDAL deviceDAL = new DeviceDAL();
            N71SPDeviceBUS n71SPDeviceBUS = new N71SPDeviceBUS();
            List<DeviceInfo> list = deviceDAL.QueryN71SPOffLine("离线");
            if (list != null)
            {
                foreach (var item in list)
                {
                    if (PingTest(item.DeviceIP))
                    {
                        bool result = n71SPDeviceBUS.LoginDevice(item.DeviceNO,item.DeviceIP, "genius", "E10ADC3949BA59ABBE56E057F20F883E", 1);
                    }
                }
            }

        }

        public bool PingTest(string ip)
        {
            try
            {
                Ping ping = new Ping();
                PingReply pingReply = ping.Send(ip);
                bool replay;
                if (pingReply.Status == IPStatus.Success)
                {
                    replay = true;
                }
                else
                {
                    replay = false;
                }
                return replay;
            }
            catch
            {
                return false;
            }
        }
    }
}
